package controller;

import java.util.ArrayList;

import model.CategoryDAO;

import com.opensymphony.xwork2.ActionSupport;

import entity.Category;

public class AdminCategoryAction extends ActionSupport {

    /** serialVersionUID. */
    private static final long serialVersionUID = 1L;

    private ArrayList<Category> listCategory;

    private CategoryDAO categoryDAO;

    private int categoryId;

    private Category category;

    private String categoryName;

    /**
     * Load template on Admin page.
     * @return index.jsp
     * @throws Exception
     */
    public String loadCategory() throws Exception {

        /** Load Category of Web */
        categoryDAO = new CategoryDAO();
        listCategory = categoryDAO.getList();

        return "SUCCESS";
    }

    public String deleteCategory() throws Exception {
        categoryDAO = new CategoryDAO();
        category = new Category();
        category = categoryDAO.find(categoryId);
        categoryDAO.delete(category);
        /** Load Category of Web */
        categoryDAO = new CategoryDAO();
        listCategory = categoryDAO.getList();
        return "SUCCESS";
    }

    public String createCategory() throws Exception {
        categoryDAO = new CategoryDAO();
        category = new Category();
        category.setCategoryName(categoryName);

        category.setSupperCategoryId(0);
        category.setActive(true);
        categoryDAO.add(category);
        
        /** Load Category of Web */
        categoryDAO = new CategoryDAO();
        listCategory = categoryDAO.getList();
        
        return "SUCCESS";
    }
    /**
     * Get value of listCategory.
     * @return the listCategory
     */
    public ArrayList<Category> getListCategory() {
        return listCategory;
    }

    /**
     * Set the value for listCategory.
     * @param listCategory the listCategory to set
     */
    public void setListCategory(ArrayList<Category> listCategory) {
        this.listCategory = listCategory;
    }

    /**
     * Get value of categoryId.
     * @return the categoryId
     */
    public int getCategoryId() {
        return categoryId;
    }

    /**
     * Set the value for categoryId.
     * @param categoryId the categoryId to set
     */
    public void setCategoryId(int categoryId) {
        this.categoryId = categoryId;
    }

    public Category getCategory() {
        return category;
    }

    public void setCategory(Category category) {
        this.category = category;
    }

    /**
     * Get value of categoryName.
     * @return the categoryName
     */
    public String getCategoryName() {
        return categoryName;
    }

    /**
     * Set the value for categoryName.
     * @param categoryName the categoryName to set
     */
    public void setCategoryName(String categoryName) {
        this.categoryName = categoryName;
    }

}
